package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported
/**
 * Controller class for the DVD collection
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * @revised version English (Ab)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class DVDCtr
{
    //declare instance variables to reference containers
    private DVDContainer dvdContainer;

    /**
     * Constructor for objects of class DVDCtr
     * 
     * Note we access the instance of DVDContainer since it is
     * a singleton container.
     */
    public DVDCtr()
    {
        dvdContainer = DVDContainer.getInstance();
        //set up references to containers    
    }
    
    /**
     * Accessor for a given DVD in the collection
     * 
     * @param int id - id of the DVD to be returned.
     * @return DVD - the DVD object returned.
     */
    public DVD getDVD(int id)
    {
        //this method is to search the container for a DVD
        //with an id-number equal to the parameter no
        //when the dvd is found, the method is to call print-methods in the TUI layer
       
        return dvdContainer.getDVD(id);
    }
    
    /**
     * Creator method for creating A DVD in the collection
     * 
     * @param String title - Title of DVD
     * @param String artist - Artist of the DVD
     * @param String releaseDate - Release date of the DVD
     * 
     * @return The created DVD object.
     */
    public DVD createDVD(String title, String artist, String releaseDate)
    {       
         //this method constructs a new dvd object 
         //and stores it in the container
        DVD d = new DVD(title, artist, releaseDate);
        dvdContainer.addDVD(d);
        return d;
    }
    
    /**
     * Mutator method to delete a DVD from the container
     * 
     * @param int id - Id of the DVD to be removed
     */
    public void deleteDVD(int id)
    {
        
        //search for the dvd and delete the object from the container
        dvdContainer.removeDVD(id);
    }
    
    /**
     * Mutator to alter a DVD in the collection
     * 
     * will overwrite the DVD object with matching id
     * 
     * @param DVD - DVD object which will overwrite in the collection
     */
    public void setDVD(DVD dvd)
    {
        dvdContainer.setDVD(dvd);
    }
    
    /**
     * Creator method for creating a copy of a given dvd
     * 
     * @param int dvdId - Id of the DVD the copy belongs to
     * @param String dateOfPurchase - Date of Purchase of the Copy
     * @param double price - Aquisition price of the Copy
     */
    public void createCopy(int dvdId, String dateOfPurchase, double price)
    {
        //create a copy of the specified dvd and add it to the dvd
        dvdContainer.getDVD(dvdId).createCopy(dateOfPurchase,price);
    }
    
    /**
     * Accessor method to get a specific copy of a DVD
     * 
     * @param int dvdId - Id of the DVD containing the copy
     * @param int serial - serial of the copy
     * 
     * @return Copy - The Copy object of the found Object. 
     */
    public Copy getCopy(int dvdId, int serial)
    {
        if(dvdContainer.getDVD(dvdId) != null)
        {
            return dvdContainer.getDVD(dvdId).getCopy(serial);
        }
        else
        {
            return null;
        }
    }
    
    /**
     * Mutator method to change a copy on a given DVD
     * 
     * Will overwrite a Copy based on matching serial 
     * 
     * @param int dvdId - Id of the DVD containing the copy
     * @param int serial - serial of the copy
     * @param Copy copy - Copy object which will overwrite in the collection
     */
    public void setCopy(int dvdId, int serial, Copy copy)
    {
        dvdContainer.getDVD(dvdId).setCopy(copy);
    }
    
    /**
     * Mutator method to remove a copy from the collection
     * 
     * @param int dvdId - Id of the DVD containing the copy
     * @param int serial - serial of the copy
     */
    public void removeCopy(int dvdId, int serial)
    {
        dvdContainer.getDVD(dvdId).removeCopy(serial);
    }
    
    /**
     * Accessor method to return a list of all DVD's
     * 
     * @return ArrayList<DVD> - List of all DVD's in collection.
     */
    public ArrayList<DVD> listAllDvds()
    {
        //returns a list of all dvds and their associated copies
        return dvdContainer.listAllDVDs();
    }
}
